﻿Public Class FormPTJNJNDJC
    Private WithEvents UcDigitalKeyboard1 As ucDigitalKeyboard
    Public usr As String
    Dim txt As TextBox
    Dim objMstTechnology As New clsMstTechnology
    Dim objPTJNJNDJC As New clsPTJNJNDJC
    Dim update_status As String = "INSERT_TYPE"
    Dim en As entityPTJNJNDJC
    Dim _sys_id As String

    Public Property Sys_id As String
        Get
            Return _sys_id
        End Get
        Set(value As String)
            _sys_id = value
        End Set
    End Property
    Private Sub FormPTJNJNDJC_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Text = GetIniFile("JS", "JS3", "", g_jsInitFileName)
        txtDate.Properties.VistaDisplayMode = DevExpress.Utils.DefaultBoolean.True
        txtDate.Properties.VistaEditTime = DevExpress.Utils.DefaultBoolean.True
        initForm()
        If _sys_id <> "" Then
            update_status = "UPDATE_TYPE"
            setContentBySysid()
        Else
            update_status = "INSERT_TYPE"
        End If
    End Sub

    Private Sub initForm()
        Dim dtMstTechnology As DataTable = objMstTechnology.getListByName(Me.Text)
        If dtMstTechnology.Rows.Count > 0 Then
            txtId.Text = dtMstTechnology.Rows(0)("sys_id").ToString()
            txtRequirement.Text = dtMstTechnology.Rows(0)("requirement").ToString()
            txtControlPoint.Text = dtMstTechnology.Rows(0)("control_point").ToString()
            Dim TDate As String = Now.ToString()
            txtDate.Text = TDate
            txt_primer_s_1.Value = 0
            txt_primer_s_2.Value = 0
            txt_primer_s_3.Value = 0
            txt_primer_s_avg.Value = 0
            txt_face_glue_s_1.Value = 0
            txt_face_glue_s_2.Value = 0
            txt_face_glue_s_3.Value = 0
            txt_face_glue_s_avg.Value = 0
        End If
    End Sub

    Private Sub setContentBySysid()
        Dim dt As DataTable = objPTJNJNDJC.selectBySysid(_sys_id)
        If dt.Rows.Count > 0 Then
            Dim row As DataRow = dt.Rows(0)
            txtRequirement.Text = row("requirement")
            txtControlPoint.Text = row("control_point")
            txtId.Text = row("technology_id")
            txtDate.Text = row("oper_date")
            txt_primer_s_1.Text = row("primer_s_1")
            txt_primer_s_2.Text = row("primer_s_2")
            txt_primer_s_3.Text = row("primer_s_3")
            txt_primer_s_avg.Text = row("primer_s_avg")
            txt_face_glue_s_1.Text = row("face_glue_s_1")
            txt_face_glue_s_2.Text = row("face_glue_s_2")
            txt_face_glue_s_3.Text = row("face_glue_s_3")
            txt_face_glue_s_avg.Text = row("face_glue_s_avg")
        End If
    End Sub

    Private Sub txt_num_MouseDown(sender As Object, e As MouseEventArgs) Handles txt_primer_s_1.MouseDown,
            txt_primer_s_2.MouseDown, txt_primer_s_avg.MouseDown, txt_face_glue_s_1.MouseDown,
            txt_face_glue_s_2.MouseDown, txt_face_glue_s_avg.MouseDown, txt_face_glue_s_3.MouseDown, txt_primer_s_3.MouseDown
        UcDigitalKeyboard1 = New ucDigitalKeyboard
        If sender.MaskBox.Mask.EditMask = "d" Then
            UcDigitalKeyboard1.B_01 = False
        Else
            UcDigitalKeyboard1.B_01 = True
        End If

        If sender.GetType().Name.Equals("TextEdit") Then
            UcDigitalKeyboard1.B_02 = True
        Else
            UcDigitalKeyboard1.B_02 = False
        End If

        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()
    End Sub

    Private Sub setEntity()
        en = New entityPTJNJNDJC
        With en
            .sys_id = _sys_id
            .factory_id = "TS"
            .technology_id = txtId.Text
            .oper_date = txtDate.Text
            .primer_s_1 = txt_primer_s_1.Text
            .primer_s_2 = txt_primer_s_2.Text
            .primer_s_3 = txt_primer_s_3.Text
            .primer_s_avg = txt_primer_s_avg.Text
            .face_glue_s_1 = txt_face_glue_s_1.Text
            .face_glue_s_2 = txt_face_glue_s_2.Text
            .face_glue_s_3 = txt_face_glue_s_3.Text
            .face_glue_s_avg = txt_face_glue_s_avg.Text
            .oper = usr
        End With
    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        If String.IsNullOrEmpty(txtDate.Text.Trim()) Then
            MsgBox("请选择操作日期", vbYes, "提示")
            Exit Sub
        End If
        setEntity()
        If update_status = "INSERT_TYPE" Then
            If objPTJNJNDJC.insert(en) <> -2 Then
                MsgBox("保存成功", vbYes, "提示")
                initForm()
            Else
                MsgBox("保存失败", vbYes, "提示")
            End If
        End If
        If update_status = "UPDATE_TYPE" Then
            If objPTJNJNDJC.update(en) <> -2 Then
                MsgBox("保存成功", vbYes, "提示")
                CType(Owner, FormGTJNJNDJCRecord).setDgvData()
                Close()
            Else
                MsgBox("保存失败", vbYes, "提示")
            End If
        End If
    End Sub

End Class

Public Class entityPTJNJNDJC
    Public sys_id As String
    Public factory_id As String '工厂ID
    Public technology_id As String '工艺ID
    Public oper_date As String '操作日期
    Public primer_s_1 As String '喷涂底胶1次
    Public primer_s_2 As String '喷涂底胶2次
    Public primer_s_3 As String '喷涂底胶3次
    Public primer_s_avg As String '喷涂底胶均值
    Public face_glue_s_1 As String '喷涂面胶1次
    Public face_glue_s_2 As String '喷涂面胶2次
    Public face_glue_s_3 As String '喷涂面胶3次
    Public face_glue_s_avg As String '喷涂面胶均值
    Public oper As String '操作人
End Class